package com.ucw.ucwclient.api.swagger;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.RequestMethod;

import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ResponseMessage;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@PropertySource("classpath:swagger.properties")
@Import(SwaggerUiConfiguration.class)
public class SwaggerConfig {

	@Bean
	public Docket customImplementation() {
		Docket docket = new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());
		docket.useDefaultResponseMessages(false);
		List<ResponseMessage> responseMessages = new ArrayList<>();
		ModelRef mr= new ModelRef("java.lang.String");
		ResponseMessage responseMessage = new ResponseMessage(500, "服务器内部错误，请稍后重试！", mr);
		responseMessages.add(responseMessage);
		docket.globalResponseMessage(RequestMethod.GET, responseMessages);
		return docket;
	}

	@Bean
	public ApiInfo apiInfo() {
		ApiInfo apiInfo = new ApiInfo("API接口管理", "内部各应用业务接口", "1.0", "", "帅气的管理员", null, null);
		return apiInfo;
	}
}
